package com.witdata.rabbit.consumer.instance;

import com.alibaba.fastjson2.JSON;
import com.witdata.rabbit.display.InstanceDisplay;
import com.witdata.rabbit.domain.Handle;
import com.witdata.rabbit.domain.HandleStatus;
import lombok.RequiredArgsConstructor;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

@Component
@RequiredArgsConstructor
public class RegisterConsumer {
    private final InstanceDisplay instanceDisplay;

    @RabbitListener(queues = "/server/recv")
    public void receive(String message) {
        System.out.println(message);
        HandleStatus handleStatus = JSON.parseObject(message, HandleStatus.class);
        if (handleStatus.getHandle() == Handle.RegisterInstance) {
            instanceDisplay.registerInstance(handleStatus.getData());
        }
    }

}
